package com.study

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.launcher.ARouter
import com.study.base.ServiceFactory
import io.reactivex.Observable
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.sdk27.coroutines.onClick


/**
 * <pre>
 *     author : fauks
 *     time   : 2020/03/11
 *     desc   :
 * </pre>
 */
class MainActivity : AppCompatActivity() {
    private val hotService by lazy {
        ServiceFactory.INSTANCE.hotService
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // testComponse()
        myTest()
    }

    private fun myTest() {
        val observable = Observable.create<String> { emitter ->
            emitter.onNext("hello")
            emitter.onComplete()
        }

        observable.map { h ->
            h.toInt()
        }.subscribe({ next -> Log.i("fauks", "msg=$next") },
                { error -> Log.i("fauks", "msg error=$error") }, {
            Log.i("fauks", "msg complete")
        })
    }

    private fun testComponse() {
        val hotModuleName = hotService?.getModuleName()
        toHot.text = hotModuleName
        toHot.onClick {
            ARouter.getInstance().build("/hot/hot").navigation()
        }
    }
}